<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <input type="hidden" id="get_error" value="${error}"/> 
        <input type="hidden" id="get_name" value="${name}"/>
        <%
        session.removeAttribute("error");
        session.removeAttribute("name");
        %>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Sign Up</title>
        <script type="text/javascript">
		window.onload = function () {
			document.getElementById("error_msg").innerHTML=document.getElementById("get_error").value;
            document.getElementById("username_text").value = document.getElementById("get_name").value;
			}
        function isEmpty(){
            var flag=false;
            var patrn1=/^(\w){1,25}$/;
            if((document.getElementById("username_text").value)==""){
                alert("username is empty!");
                return false;
            }
            else if(!patrn1.exec(document.getElementById("username_text").value)){
            	alert("username format error or too long!");
            	return false;
            }
            else if((document.getElementById("password").value)==""){
                alert("password is empty!");
              return false;  
            } 
            else if(!patrn1.exec(document.getElementById("password").value)){
            	alert("password can't be too long!");
            	return false;
            }
            else if((document.getElementById("password").value)!=(document.getElementById("passwordconfirm").value)){
                alert("password confirm is different from password!");
              return false;  
            } 
            else return true;
            }


            
         
        </script>
        <link rel="stylesheet" type="text/css" href="main.css">
    </head>
    <body>
        <h1>Please fill the required information:</h1>
        <label id="error_msg"></label><br>
        <form action="Signup" name="regis" method="post" onsubmit="return isEmpty()">
            <table>
                <tr><td>Username:</td><td><input type="text" name="username" id="username_text" ></td><td>*only ['0'-'9'],'_',['a'-'z'] are allowed</td></tr>
                <tr><td>Password:</td><td><input type="password" name="password" id="password" ></td><td>*only ['0'-'9'],'_',['a'-'z'] are allowed</td></tr>
                <tr><td>Password Confirm:</td><td><input type="password" id="passwordconfirm"></td><td></td></tr>
            </table>
        <input type="submit" value="submit">
        </form>
    </body>
</html>